package com.itheima.controller;

import com.itheima.common.CompanyResult;
import com.itheima.common.Result;
import com.itheima.pojo.hm.HmSubjects;
import com.itheima.pojo.hm.SubjectDto;
import com.itheima.service.SubjectsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
 *@Parm
 *@ClassName SubjectsController
 *@Date 2022/1/10 11:23
 */
@RestController
@RequestMapping("/subjects")
public class SubjectsController {
    @Autowired
    private SubjectsService subjectsService;

    //修改学科
    @PutMapping("/{id}")
    public CompanyResult updateById(@PathVariable Integer id, @RequestBody HmSubjects subjects){
        return subjectsService.updateById(subjects);
    }


    //删除学科
    @DeleteMapping("/{id}")
    public CompanyResult delete(@PathVariable Integer id, @RequestBody HmSubjects subjects){
        return subjectsService.deleteById(id);
    }

    //添加学科
    @PostMapping
    public CompanyResult add(@RequestBody HmSubjects subjects){
        return subjectsService.add(subjects);
    }

//    @GetMapping("/simple")
//    public List<SubjectDto> findAll(){
//        return subjectsService.findAll();
//    }

    @GetMapping
    public Result findPage(String subjectName,Integer page,Integer pagesize){
        return subjectsService.findPage(page,pagesize,subjectName);
    }

}
